<template>
  <div>
    <Form ref="formInline" :model="map" inline>
      <div class="search">
        <Button type="primary" class="fl" icon="plus" @click="add">增加公司</Button>
        <FormItem>
          <Input type="text" v-model="map.key" placeholder="关键字"></Input>
        </FormItem>
        <FormItem>
          <Button type="primary" @click="getList">查询</Button>
        </FormItem>
      </div>
    </Form>
    <Table border stripe :loading="loading" :columns="columns" :data="data && data.data" :height="500"></Table>
    <Page class="page" :total="data && data.count" :page-size="data && data.pagesize" show-total @on-change="changePage"></Page>


  </div>
</template>
<script>
  import {company} from "@/api/supervision";
  import {Button, Form, FormItem, Input, Option, Page, Select, Table, Tag} from 'iview';

  export default {
    components: {
      Button,
      Table,
      Page,
      Form,
      FormItem,
      Input,
      Select,
      Option,
      Tag,
    },
    data() {
      return {
        loading: true,
        columns: [
          {
            title: "公司名称",
            key: "title"
          },
          {
            title: "公司地址",
            key: "address"
          },
          {
            title: "银行账号",
            key: "bank_account"
          },
          {
            title: "开户银行",
            key: "bank_name"
          },
          {
            title: "操作",
            key: "action",
            width: 250,
            align: "center",
            render: (h, params) => {
              return h("div", [
                h(
                  "Button",
                  {
                    props: {
                      type: "primary",
                      size: "small",
                      // icon: 'ios-list'
                    },
                    style: {
                      marginRight: "5px"
                    },
                    on: {
                      click: () => {
                        this.$router.push({
                          path: "/supervision/user/list",
                          query: {
                            company_id: params.row.id
                          }
                        });
                      }
                    }
                  },
                  '干系人'
                ),
                h(
                  "Button",
                  {
                    props: {
                      type: "primary",
                      size: "small",
                      // icon: 'ios-list'
                    },
                    style: {
                      marginRight: "5px"
                    },
                    on: {
                      click: () => {
                        this.$router.push({
                          path: "/supervision/company/save",
                          query: {
                            id: params.row.id
                          }
                        });
                      }
                    }
                  },
                  '编辑'
                ),
                h(
                  "Button",
                  {
                    props: {
                      type: "error",
                      size: "small",
                      // icon: 'trash'
                    },
                    on: {
                      click: () => {
                        if(confirm("确定要删除吗？")) {
                          this.delete(params.row.id, params.index);
                        }
                      }
                    }
                  },
                  '删除'
                )
              ]);
            }
          }
        ],
        data: {},
        map: {
          page: 1,
          key: "",
          pageSize: 10,
        },
      };
    },
    methods: {
      getList() {
        this.loading = true;
        company.getList(this.map).then(res => {
          this.data = res.data;
          this.loading = false;
        });
      },
      delete(id, index) {
        company.delete(id).then(res => {
          // this.data.splice(index, 1);
          this.getList();
        });
      },
      changePage(index) {
        this.map.page = index;
        this.getList();
      },
      add() {
        this.$router.push('/supervision/company/save');
      },

    },
    mounted() {
      //if(this.$route.query.role_id) {
      //  this.map.role_id = this.$route.query.role_id;
      //}

      this.getList();
    }
  };
</script>
